home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_110 / mint / bash110s.zoo / bash-1.10 / shell.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-30  |  8.4 KB  |  240 lines

  1. /* shell.h -- The data structures used by the shell */
  2.  
  3. #include "config.h"
  4. #include "general.h"
  5. #include "variables.h"
  6. #include "quit.h"
  7. #include "maxpath.h"
  8. #include "unwind_prot.h"
  9.  
  10. extern int EOF_Reached;
  11.  
  12. #define NO_PIPE -1
  13. #define REDIRECT_BOTH -2
  14. #define IS_DESCRIPTOR -1
  15.  
  16. #define NO_VARIABLE -1
  17.  
  18. /* A bunch of stuff for flow of control using setjmp () and longjmp (). */
  19.  
  20. #include <setjmp.h>
  21. extern jmp_buf top_level, catch;
  22.  
  23. #define NOT_JUMPED 0        /* Not returning from a longjmp. */
  24. #define FORCE_EOF 1        /* We want to stop parsing. */
  25. #define DISCARD 2        /* Discard current command. */
  26. #define EXITPROG 3        /* Unconditionally exit the program now. */
  27.  
  28. /* Values that can be returned by execute_command (). */
  29. #define EXECUTION_FAILURE 1
  30. #define EXECUTION_SUCCESS 0
  31.  
  32. /* Special exit status used when the shell is asked to execute a
  33.    binary file as a shell script. */
  34. #define EX_BINARY_FILE 126
  35.  
  36. /* The list of characters that are quoted in double-quotes with a
  37.    backslash.  Other characters following a backslash cause nothing
  38.    special to happen. */
  39. #define slashify_in_quotes "\\`$\""
  40. #define slashify_in_here_document "\\`$"
  41.  
  42. /* Constants which specify how to handle backslashes and quoting in
  43.    expand_word_internal ().  Q_DOUBLE_QUOTES means to use the function
  44.    slashify_in_quotes () to decide whether the backslash should be
  45.    retained.  Q_HERE_DOCUMENT means slashify_in_here_document () to
  46.    decide whether to retain the backslash.  Q_KEEP_BACKSLASH means
  47.    to unconditionally retain the backslash. */
  48. #define Q_DOUBLE_QUOTES  0x1
  49. #define Q_HERE_DOCUMENT  0x2
  50. #define Q_KEEP_BACKSLASH 0x4
  51.  
  52. /* All structs which contain a `next' field should have that field
  53.    as the first field in the struct.  This means that functions
  54.    can be written to handle the general case for linked lists. */
  55. typedef struct g_list {
  56.   struct g_list *next;
  57. } GENERIC_LIST;
  58.  
  59. /* Instructions describing what kind of thing to do for a redirection. */
  60. enum r_instruction { r_output_direction, r_input_direction, r_inputa_direction,
  61.              r_appending_to, r_reading_until, r_duplicating,
  62.              r_deblank_reading_until, r_close_this, r_err_and_out,
  63.              r_input_output, r_output_force };
  64.  
  65. /* Command Types: */
  66. enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple,
  67.             cm_connection, cm_function_def, cm_until, cm_group };
  68.  
  69. /* A structure which represents a word. */
  70. typedef struct word_desc {
  71.   char *word;            /* Zero terminated string. */
  72.   int dollar_present;        /* Non-zero means dollar sign present. */
  73.   int quoted;            /* Non-zero means single, double, or back quote
  74.                    or backslash is present. */
  75.   int assignment;        /* Non-zero means that this word contains an assignment. */
  76. } WORD_DESC;
  77.  
  78. /* A linked list of words. */
  79. typedef struct word_list {
  80.   struct word_list *next;
  81.   WORD_DESC *word;
  82. } WORD_LIST;
  83.  
  84.  
  85. /* **************************************************************** */
  86. /*                                    */
  87. /*            Shell Command Structs                */
  88. /*                                    */
  89. /* **************************************************************** */
  90.  
  91. /* What a redirection descriptor looks like.  If FLAGS is IS_DESCRIPTOR,
  92.    then we use REDIRECTEE.DEST, else we use the file specified. */
  93. typedef struct redirect {
  94.   struct redirect *next;    /* Next element, or NULL. */
  95.   int redirector;        /* Descriptor to be redirected. */
  96.   int flags;            /* Flag value for `open'. */
  97.   enum r_instruction  instruction; /* What to do with the information. */
  98.   union {
  99.     int dest;            /* Place to redirect REDIRECTOR to, or ... */
  100.     WORD_DESC *filename;    /* filename to redirect to. */
  101.   } redirectee;
  102.   char *here_doc_eof;        /* The word that appeared in <<foo. */
  103. } REDIRECT;
  104.  
  105. /* An element used in parsing.  A single word or a single redirection.
  106.    This is an ephemeral construct. */
  107. typedef struct element {
  108.   WORD_DESC *word;
  109.   REDIRECT *redirect;
  110. } ELEMENT;
  111.  
  112. /* Possible values for command->flags. */
  113. #define CMD_WANT_SUBSHELL  0x01    /* User wants a subshell: ( command ) */
  114. #define CMD_FORCE_SUBSHELL 0x02    /* Shell needs to force a subshell. */
  115. #define CMD_INVERT_RETURN  0x04    /* Invert the exit value. */
  116. #define CMD_IGNORE_RETURN  0x08    /* Ignore the exit value.  For set -e. */
  117. #define CMD_NO_FUNCTIONS   0x10 /* Ignore functions during command lookup. */
  118. #define CMD_INHIBIT_EXPANSION 0x20 /* Do not expand the command words. */
  119.  
  120. /* What a command looks like. */
  121. typedef struct command {
  122.   enum command_type type;    /* FOR CASE WHILE IF CONNECTION or SIMPLE. */
  123.   int flags;            /* Flags controlling execution environment. */
  124.   REDIRECT *redirects;        /* Special redirects for FOR CASE, etc. */
  125.   union {
  126.     struct for_com *For;
  127.     struct case_com *Case;
  128.     struct while_com *While;
  129.     struct if_com *If;
  130.     struct connection *Connection;
  131.     struct simple_com *Simple;
  132.     struct function_def *Function_def;
  133.     struct group_com *Group;
  134.   } value;
  135. } COMMAND;
  136.  
  137. /* Structure used to represent the CONNECTION type. */
  138. typedef struct connection {
  139.   int ignore;            /* Unused; simplifies make_command (). */
  140.   COMMAND *first;        /* Pointer to the first command. */
  141.   COMMAND *second;        /* Pointer to the second command. */
  142.   int connector;        /* What separates this command from others. */
  143. } CONNECTION;
  144.  
  145. /* Structures used to represent the CASE command. */
  146.  
  147. /* Pattern/action structure for CASE_COM. */
  148. typedef struct pattern_list {
  149.   struct pattern_list *next;    /* Clause to try in case this one failed. */
  150.   WORD_LIST *patterns;        /* Linked list of patterns to test. */
  151.   COMMAND *action;        /* Thing to execute if a pattern matches. */
  152. } PATTERN_LIST;
  153.  
  154. /* The CASE command. */
  155. typedef struct case_com {
  156.   int flags;            /* See description of CMD flags. */
  157.   WORD_DESC *word;        /* The thing to test. */
  158.   PATTERN_LIST *clauses;    /* The clauses to test against, or NULL. */
  159. } CASE_COM;
  160.  
  161. /* FOR command. */
  162. typedef struct for_com {
  163.   int flags;        /* See description of CMD flags. */
  164.   WORD_DESC *name;    /* The variable name to get mapped over. */
  165.   WORD_LIST *map_list;    /* The things to map over.  This is never NULL. */
  166.   COMMAND *action;    /* The action to execute.
  167.                During execution, NAME is bound to successive
  168.                members of MAP_LIST. */
  169. } FOR_COM;
  170.  
  171. /* IF command. */
  172. typedef struct if_com {
  173.   int flags;            /* See description of CMD flags. */
  174.   COMMAND *test;        /* Thing to test. */
  175.   COMMAND *true_case;        /* What to do if the test returned non-zero. */
  176.   COMMAND *false_case;        /* What to do if the test returned zero. */
  177. } IF_COM;
  178.  
  179. /* WHILE command. */
  180. typedef struct while_com {
  181.   int flags;            /* See description of CMD flags. */
  182.   COMMAND *test;        /* Thing to test. */
  183.   COMMAND *action;        /* Thing to do while test is non-zero. */
  184. } WHILE_COM;
  185.  
  186. /* The "simple" command.  Just a collection of words and redirects. */
  187. typedef struct simple_com {
  188.   int flags;            /* See description of CMD flags. */
  189.   WORD_LIST *words;        /* The program name, the arguments,
  190.                    variable assignments, etc. */
  191.   REDIRECT *redirects;        /* Redirections to perform. */
  192. } SIMPLE_COM;
  193.  
  194. /* The "function_def" command.  This isn't really a command, but it is
  195.    represented as such for now.  If the function def appears within 
  196.    `(' `)' the parser tries to set the SUBSHELL bit of the command.  That
  197.    means that FUNCTION_DEF has to be run through the executor.  Maybe this
  198.    command should be defined in a subshell.  Who knows or cares. */
  199. typedef struct function_def {
  200.   int ignore;            /* See description of CMD flags. */
  201.   WORD_DESC *name;        /* The name of the function. */
  202.   COMMAND *command;        /* The parsed execution tree. */
  203. } FUNCTION_DEF;
  204.  
  205. /* A command that is `grouped' allows pipes to take effect over
  206.    the entire command structure. */
  207. typedef struct group_com {
  208.   int ignore;            /* See description of CMD flags. */
  209.   COMMAND *command;
  210. } GROUP_COM;
  211.   
  212. /* Forward declarations of functions called by the grammer. */
  213. extern REDIRECT *make_redirection ();
  214. extern WORD_LIST *make_word_list ();
  215. extern WORD_DESC *make_word ();
  216.  
  217. extern COMMAND
  218.   *make_for_command (), *make_case_command (), *make_if_command (),
  219.   *make_while_command (), *command_connect (), *make_simple_command (),
  220.   *make_function_def (), *clean_simple_command (), *make_until_command (),
  221.   *make_group_command ();
  222.  
  223. extern PATTERN_LIST *make_pattern_list ();
  224. extern COMMAND *global_command, *copy_command ();
  225.  
  226. extern char **shell_environment;
  227. extern WORD_LIST *rest_of_args;
  228.  
  229. /* Generalized global variables. */
  230. extern int executing, login_shell;
  231.  
  232. /* Structure to pass around that holds a bitmap of file descriptors
  233.    to close, and the size of that structure.  Used in execute_cmd.c. */
  234. struct fd_bitmap {
  235.   long size;
  236.   char *bitmap;
  237. };
  238.  
  239. #define FD_BITMAP_SIZE 32
  240.